unit acroMultiDesignEditor;
{$I acroMultiLang.inc}
interface
uses
  {$IFDEF Delphi5High}
  VclEditors,DesignEditors,DesignIntf,
  {$ELSE}
  DsgnIntf,
  {$ENDIF}
  SysUtils,Windows;

type
  TacroComponentEditor=class(TComponentEditor)
   public
    function GetVerb(Index:Integer):string;override;
    function GetVerbCount:Integer;override;
  end;

  function GetPackageVersion:string;

ResourceString
  S_LoadDic='Load dictionary from file...';
  S_SaveDic='Save dictionary to file ...';
  S_ClearDic='Clear dictionary';
  S_ProductName='acro Multi-Language Suite';

implementation

function VersionString(Ms,Ls:Longint):String;
begin
  Result:=Format('%d.%d.%d.%d',[HIWORD(Ms),LOWORD(Ms),HIWORD(Ls),LOWORD(Ls)]);
end;

function GetPackageVersion:string;
const
  VerTranslation:PChar='\VarFileInfo\Translation';
var
  SBSize:UInt;
  Size:Cardinal;
  Handle:DWord;
  B:TMemoryBasicInformation;
  vFileName,RezBuffer:string;
  TransTable: PLongint;
  FixedFileInfoBuf: PVSFixedFileInfo;
begin
  Result:='';
  Windows.VirtualQuery(TacroComponentEditor,B,SizeOf(B));
  vFileName:=SysUtils.GetModuleName(HModule(B.AllocationBase));
  Size:=GetFileVersionInfoSize(PChar(vFileName),Handle);
  if Size<=0 then exit;
  SetLength(RezBuffer,Size);
  if not GetFileVersionInfo(PChar(vFileName),Handle,Size,PChar(RezBuffer)) then exit;
  if not VerQueryValue(PChar(RezBuffer),VerTranslation,pointer(TransTable),SBSize) then exit;
  if VerQueryValue(PChar(RezBuffer),'\',Pointer(FixedFileInfoBuf),Size) then
  begin
    if Size<>SizeOf(TVSFixedFileInfo) then exit;
    Result:=VersionString(FixedFileInfoBuf^.dwFileVersionMS,FixedFileInfoBuf^.dwFileVersionLS);
  end;
end;

{ TacroComponentEditor }

function TacroComponentEditor.GetVerb(Index: Integer): string;
begin
  Result:='';
  if Index=GetVerbCount-2 then Result:='-'
  else if Index=GetVerbCount-1 then Result:=S_ProductName+' '+GetPackageVersion;
end;

function TacroComponentEditor.GetVerbCount: Integer;
begin
  Result:=2;
end;

end.
